<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<t:base type="jquery,easyui,tools,DatePicker"></t:base>
<html>
<head>
    <title>CSA发货</title>
    <script>
        $(document).ready(function () {
            var list = '${stringList}';
            var list1 = list.toString();
            var newstr=list1.substring(1,list1.length-1);
            var values = $("#ids").val(newstr);
        })
        // $(function (){
        //     var logisticsName = $("#logistics").val();
        //     var cityId = $("#cityId").val();
        //     if(logisticsName!="" || logisticsName!=null){
        //         $.ajax({
        //             type:"GET",
        //             data:{"logisticsName":logisticsName,"cityId":cityId},
        //             url:"cbsDelinerController.do?getSLA",
        //             dataType:"json",
        //             success:function (data) {
        //                 var obj = data.obj;
        //                 if(obj==null){
        //                     $("#slaType").text("无");
        //                 }
        //                 var slaType =  obj.slaType;
        //                 if (slaType=="1"){
        //                     $("#slaType").text("SL1");
        //                 }
        //                 if (slaType=="2"){
        //
        //                     $("#slaType").text("SL2");
        //                 }
        //                 if (slaType=="3"){
        //                     $("#slaType").text("SL3");
        //                 }
        //                 if (slaType=="4"){
        //                     $("#slaType").text("SL4");
        //                 }
        //             }
        //         })
        //     }
        // })
        $(function () {
            var id = $('#province').val();
            $.post('loginWxController.do?getTerritoryCity', {id: id}, function (data) {
                data = $.parseJSON(data);
                $('#city').find('option').remove();
                var str = "";
                for (var i = 0; i < data.length; i++) {
                    str += '<option value="' + data[i].id + '">' + data[i].territoryName + '</option>';
                }
                $('#city').append(str);
                if (cityId != '') {
                    $('#city').val(cityId);
                }
            });
            //界面加载物流联系人
            var return_logistics = $("#logistics").val();
            $.ajax({
                type:"post",
                dataType:"json",
                url:"cbsWarehouseController.do?getPersonMessage",
                data:{"logistics":return_logistics},
                success:function (data) {
                    var obj = data.obj;
                    var  html = "";
                    var name = "";
                    var phone="";
                    var email = "";
                    for ( i in obj){
                        if (obj[i].name==null){
                            name+="";
                        }else {
                            name+=obj[i].name;
                        }
                        if (obj[i].cellphone1==null){
                            phone+="";
                        }else {
                            phone+=obj[i].cellphone1;
                        }
                        if (obj[i].email==null){
                            email+="";
                        }else {
                            email+=obj[i].email;
                        }
                        html+="<span>"+name+"&nbsp;"+phone+"&nbsp;"+email+"</span><br>";
                    }
                    $("#personLabel").html(html);
                    $("#personMsg").html(html);
                }
            });
            //加载仓库联系人
            var warehouse = $("#warehouse").val();
            $.ajax({
                type:"post",
                dataType:"json",
                data:{"warehouse":warehouse},
                url:"cbsDelinerController.do?getWarehousePerson",
                success:function (data) {
                    var obj = data.obj;
                    if(obj!=null){
                        var  html = "";
                        var name = "";
                        var phone="";
                        var email = "";

                        if (obj.userName==null){
                            name+="";
                        }else {
                            name+=obj.userName;
                        }
                        if (obj.phone==null){
                            phone+="";
                        }else {
                            phone+=obj.phone;
                        }
                        if (obj.email==null){
                            email+="";
                        }else {
                            email+=obj.email;
                        }
                        html+="<span>"+name+"&nbsp;"+phone+"&nbsp;"+email+"<span";
                    }

                    $("#warehousePerson").html(html);
                }


            })
        })
        //二级联动
        function loadCity() {
            var id = $('#province').val();
            $.post('loginWxController.do?getTerritoryCity', {id: id}, function (data) {
                data = $.parseJSON(data);
                $('#city').find('option').remove();
                var str = "";
                for (var i = 0; i < data.length; i++) {
                    str += '<option value="' + data[i].id + '">' + data[i].territoryName + '</option>';
                }
                $('#city').append(str);
                // if (cityId != '') {  cityId
                //     $('#city').val(cityId);
                // }
            });

        }
        $(function (){
            var logisticsName = $("#logistics").val();
            var cityId = $("#cityId").val();
            if(logisticsName!="" || logisticsName!=null){
                $.ajax({
                    type:"post",
                    data:{"logisticsName":logisticsName,"cityId":cityId},
                    url:"cbsDelinerController.do?getSLA",
                    dataType:"json",
                    success:function (data) {
                        var obj = data.obj;
                        if(obj==null){
                            $("#slaType").text("无");
                        }
                        if(obj!=null){
                            var slaType =  obj.slaType;
                            $("#slaType").text(slaType);
                        }
                    }
                })
            }
        })
        function getSLA() {
            var logisticsName = $("#logistics").val();
            var cityId = $("#cityId").val();
            if(logisticsName!="" || logisticsName!=null){
                $.ajax({
                    type:"post",
                    data:{"logisticsName":logisticsName,"cityId":cityId},
                    url:"cbsDelinerController.do?getSLA",
                    dataType:"json",
                    success:function (data) {
                        var obj = data.obj;
                        if(obj==null){
                            $("#slaType").text("无");
                        }
                        if(obj!=null){
                            var slaType =  obj.slaType;
                            $("#slaType").text(slaType);
                        }
                    }
                })
            }
        }
        function getPersonMessage() {
            var return_logistics = $("#return_logistics").val();
            $.ajax({
                type:"post",
                dataType:"json",
                url:"cbsWarehouseController.do?getPersonMessage",
                data:{"logistics":return_logistics},
                success:function (data) {
                    var obj = data.obj;
                   var  html = "";
                   var name = "";
                   var phone="";
                   var email = "";
                    if (obj==null || obj==""){
                        html += '<label>暂无联系人信息</label>';
                    }else {
                        for ( i in obj){
                            if (obj[i].name==null){
                                name+="";
                            }else {
                                name+=obj[i].name;
                            }
                            if (obj[i].cellphone1==null){
                                phone+="";
                            }else {
                                phone+=obj[i].cellphone1;
                            }
                            if (obj[i].email==null){
                                email+="";
                            }else {
                                email+=obj[i].email;
                            }
                            html+="<span>"+name+"&nbsp;"+phone+"&nbsp;"+email+"</span>";
                        }
                    }

                    $("#personMsg").html(html);
                }
            })

        }
        function getPersonLabel() {
            var return_logistics = $("#logistics").val();
            $.ajax({
                type:"post",
                dataType:"json",
                url:"cbsWarehouseController.do?getPersonMessage",
                data:{"logistics":return_logistics},
                success:function (data) {
                    var obj = data.obj;

                    var  html = "";
                    var name = "";
                    var phone="";
                    var email = "";
                    // alert(obj);
                    if (obj==null || obj==""){
                        html += '<label>暂无联系人信息</label>';
                    }else{
                        for ( i in obj){
                            if (obj[i].name==null){
                                name+="";
                            }else {
                                name+=obj[i].name;
                            }
                            if (obj[i].cellphone1==null){
                                phone+="";
                            }else {
                                phone+=obj[i].cellphone1;
                            }
                            if (obj[i].email==null){
                                email+="";
                            }else {
                                email+=obj[i].email;
                            }
                            html+="<span>"+name+"&nbsp;"+phone+"&nbsp;"+email+"</span>";
                        }
                    }

                    $("#personLabel").html(html);
                }
            })
        }
        function getWarehouseByLogistics() {

            var city = $("#cityId").val();
            var logistics = $("#logistics").val();
            if (logistics=="0"){
                getCang();
            }else {
                $.ajax({
                    type:"post",
                    data:{"cityCode":city,"logistics":logistics},
                    url:"cbsDelinerController.do?getWarehouseByLogistics",
                    dataType:"json",
                    success:function (data) {
                        var tbs = data.obj;

                        if(tbs==null){
                            $("#warehouse").html("<option value=''>--请选择仓库--</option>");
                            $("#warehousePerson").html('暂无联系人');
                        }else{
                            var html = "<option value='0'>--请选择仓库--</option>";
                            for (i in tbs){
                                html +="<option value='"+tbs[i].id+"'>"+tbs[i].name+"</option>";

                            }
                            $("#warehouse").html(html);
                            var cityId = $("#cityId").val();
                            if(cityId!=""){
                                $.ajax({
                                    type:"GET",
                                    data:{"cityCode":cityId,"logistics":logistics},
                                    url:"cbsDelinerController.do?getWarehouseByLogisticsForCity",
                                    dataType:"json",
                                    success:function (data) {
                                        var obj = data.obj;
                                        $('#warehouse option').each(function(){
                                            if($(this).val()==obj[0].id ){
                                                $(this).attr("selected",true);
                                            }
                                        })
                                        getWarehouseContacts();
                                    }
                                })
                            }
                            // $("#warehouseContacts").html('<label>'+tbs[0].userName+'&nbsp &nbsp '+tbs[0].phone+'&nbsp &nbsp'+tbs[0].email+'</label>')

                        }
                        // getFhContacts();
                        getWarehouseContacts();
                    }
                })
            }

        }
        function getWarehouseContacts(){

            var deliverWarehouseId = $("#warehouse").val();
            // alert(deliverWarehouseId)
            if(deliverWarehouseId=="0"){
                $("#warehousePerson").html('<label>暂无联系人信息</label>');
            }else{
                $.ajax({
                    type:"post",
                    data:{"code":deliverWarehouseId},
                    url:"cbsDelinerController.do?getWarehouseContacts",
                    dataType:"json",
                    success:function (data) {
                        var tbs = data.obj;
                        var name=tbs.userName;
                        var phone=tbs.phone;
                        var email=tbs.email;

                        if(tbs.userName==null){
                            name="";
                        }
                        if(tbs.phone==null){
                            phone=="";
                        }
                        if(tbs.email==null){
                            email=="";
                        }
                        if(tbs.email==null && tbs.userName==null &&tbs.phone==null){
                            html = '<label>暂无联系人信息</label>';
                        }else{
                            html = '<label>'+name+'&nbsp &nbsp '+phone+'&nbsp &nbsp'+email+'</label>';
                        }
                        $("#warehousePerson").html(html);
                        console.log("contects:"+tbs)
                    }

                })
            }

        }

        function getCang() {

            var cityId = $("#cityId").val();
            var logistics = $("#logistics").val();
            $.ajax({
                type:"post",
                data:{"cityCode":cityId,"logistics":logistics},
                url:"cbsDelinerController.do?getWarehouseByLogistics",
                dataType:"json",
                success:function (data) {
                    var obj = data.obj;
                    var html = "<option value='0'>--请选择仓库--</option>";
                    for (i in obj){
                        html+="<option value='"+obj[i].id+"'>"+obj[i].name+"</option>";
                    }
                    $("#warehouse").html(html);
                    getWarehouseContacts();
                }
            })
        }
        function getSLAByWarsoue() {
            var logisticsName = $("#logistics").val();
            var cityId = $("#cityId").val();
            var deliverWarehouseId = $("#warehouse").val();
            if(logisticsName!="" || logisticsName!=null){
                $.ajax({
                    type:"post",
                    data:{"logisticsName":logisticsName,"cityId":cityId,"deliverWarehouseId":deliverWarehouseId},
                    url:"cbsDelinerController.do?getSLAByWarouse",
                    dataType:"json",
                    success:function (data) {
                        var obj = data.obj;
                        if(obj==null){
                            $("#slaType").text("无");
                        }
                        if(obj!=null){
                            var slaType =  obj.slaType;
                            $("#slaType").text(slaType);
                        }
                    }
                })
            }
        }
        function getWarehousePerson() {
            var warehouse = $("#warehouse").val();
            $.ajax({
                type:"post",
                dataType:"json",
                data:{"warehouse":warehouse},
                url:"cbsDelinerController.do?getWarehousePerson",
                success:function (data) {
                    var obj = data.obj;
                    if(obj!=null){
                        var  html = "";
                        var name = "";
                        var phone="";
                        var email = "";

                        if (obj.userName==null){
                            name+="";
                        }else {
                            name+=obj.userName;
                        }
                        if (obj.phone==null){
                            phone+="";
                        }else {
                            phone+=obj.phone;
                        }
                        if (obj.email==null){
                            email+="";
                        }else {
                            email+=obj.email;
                        }
                        html+="<span>"+name+"&nbsp;"+phone+"&nbsp;"+email+"<span";
                    }

                    $("#warehousePerson").html(html);
                }


            })
        }
    </script>
</head>
<body>
<div><span style="font-weight: bold;">发货单</span></div>
<div class="line"></div>
<table class="ftable">
    <tbody>
    <tr>
        <th>备件类型</th>
        <th>备件号</th>
        <th>备件序列号</th>
        <th>数量</th>
        <th>优先级</th>
        <th>是否返件</th>
    </tr>
    <c:forEach items="${cbsDeliverEquipmentEntityList2}" var="deliver">
        <tr>
            <td>${deliver.typeDes}</td>
            <td>${deliver.itemId.item}</td>
            <td>${deliver.sn}</td>
            <td>${deliver.total}</td>
            <td>
                <c:if test="${deliver.applyLayer==1}">低</c:if>
                <c:if test="${deliver.applyLayer==2}">中</c:if>
                <c:if test="${deliver.applyLayer==3}">高</c:if>
                <c:if test="${deliver.applyLayer==4}">加急</c:if>
            </td>
            <td>
                <c:if test="${deliver.isReturn!=2}">否</c:if>
                <c:if test="${deliver.isReturn==2}">是</c:if>
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>
<div class="line"></div>
<form id="myform" name="myform">
    <input type="hidden" name="warehouseId.id" value="${cbsDelinerEntity.warehouseId.id}"/>
    <input type="hidden" name="srCode" value="${cbsDelinerEntity.srCode}"/>
    <input type="hidden" name="soCode" value="${cbsDelinerEntity.soCode}"/>
    <input type="hidden" name="crCode" value="${cbsDelinerEntity.crCode}"/>
    <input type="hidden" value=" ${cbsDelinerEntity.sheng.id}" name="sheng.id"/>
    <input type="hidden" value=" ${cbsDelinerEntity.shi.id}" name="shi.id"/>
    <input type="hidden" value=" ${cbsDelinerEntity.address}" name="address"/>
    <input type="hidden" value="${cbsDelinerEntity.equipmentApplyId.id}" name="equipmentApplyId.id"/>
    <%--<input type="hidden" value="${cbsDelinerPage.thAddress}" name="thAddress"/>--%>
    <input type="hidden" id="logisticsName" value="${logisticsName}"/>
    <input  type="hidden" value="${cbsDelinerEntity.deliverType}" name="deliverType"/>
    <div><span style="font-weight: bold;">收货人</span></div>
<table class="nobordertable noborder" style="border: none;">
    <tbody>
    <tr>
        <td class="al_r" width="20%">
            <label>姓名:</label>
        </td>
        <td width="30%">
            ${cbsDelinerEntity.userName}
            <input type="hidden" value="${cbsDelinerEntity.userName}" name="userName"/>
        </td>
        <td class="al_r" width="20%">
            <label>电话:</label>
        </td>
        <td width="30%">
            ${cbsDelinerEntity.phone}
                <input type="hidden" value=" ${cbsDelinerEntity.phone}" name="phone"/>
        </td>
    </tr>
    <tr>
        <td class="al_r" width="20%">
            <label>收货地址:</label>
        </td>
        <td colspan="3">
            <input type="hidden" value="${cbsDelinerEntity.shi.id}" id="cityId" />
            ${cbsDelinerEntity.sheng.territoryName} ${cbsDelinerEntity.shi.territoryName} ${cbsDelinerEntity.address}

        </td>
    </tr>
    <tr>
        <td class="al_r" width="20%">
            <label>影院名称:</label>
        </td>
        <td width="30%">
            ${cbsDelinerEntity.cinemaName}
            <input  type="hidden" value="${cbsDelinerEntity.cinemaName}" name="cinemaName"/>
        </td>
        <td class="al_r" width="20%">
            <label>是否自提:</label>
        </td>
        <td width="30%">
            <c:if test="${cbsDelinerEntity.zt ==2}">是</c:if>
            <c:if test="${cbsDelinerEntity.zt !=2}">否</c:if>
            <input  type="hidden" value="${cbsDelinerEntity.zt}" name="zt"/>
        </td>
    </tr>
    <tr>
        <td class="al_r" width="20%" valign="top">
            <label>CSA注意事项:</label>
        </td>
        <td colspan="3">
            <textarea style="width: 100%; height: 60px;" readonly="readonly">${cbsDelinerEntity.equipmentApplyId.csaAttention}</textarea>

        </td>
    </tr>
    </tbody>
</table>
<div><span style="font-weight: bold;">选择发货物流</span></div>

<table class="nobordertable noborder" style="border: none;">
    <tbody>
    <tr>
        <td class="al_r" width="20%">
            <label>物流:</label>
        </td>
        <td width="30%">
            <input type="hidden" value="${cbsWarehouseEntityList}" id="priority">
            <select id="logistics" onchange="getSLA();getPersonLabel();getWarehouseByLogistics()" name="deliverLogistics">
                <option value="0">--请选择物流--</option>
                <c:forEach items="${tsDepartList}" var="tsDe">
                    <option value="${tsDe.departname}" <c:if test="${cbsDelinerEntity.deliverLogistics == tsDe.departname}">selected="selected"</c:if>>${tsDe.departname}</option>
                </c:forEach>
            </select>
        </td>
        <td class="al_r" width="20%">
            <label>联系人:</label>
        </td>
        <td width="30%">
            <span id="personLabel">${zyContacts.name}&emsp;${zyContacts.cellphone1}&emsp;${zyContacts.email}</span>
        </td>
    </tr>
    <tr>
        <td class="al_r" width="20%">
            <label>仓库:</label>
        </td>
        <td width="30%">
            <input type="hidden" value="${cbsWarehouseEntity.name}" id="cbsWarehouseEntity"/>
            <select id="warehouse" name="deliverWarehouseId.id" onchange="getWarehousePerson();getSLAByWarsoue()">
                <option value="0">--请选择仓库--</option>
                <c:forEach items="${wareList}" var="ware">
                    <option value="${ware.id}" <c:if test="${ware.name == warehouseName}">selected="selected"</c:if>>${ware.name}</option>
                </c:forEach>

            </select>
        </td>
        <td class="al_r" width="20%">
            <label>联系人:</label>
        </td>
        <td width="30%">
            <span id="warehousePerson"></span>
        </td>
    </tr>
    <tr>
        <td class="al_r" width="20%">
            <%--<input type="hidden" value="${slaId}" id="sla"/>--%>
            <label>物流承诺SLA:</label>
        </td>
        <td colspan="3">
            <span id="slaType"></span>
            <input type="hidden" id="wlSLA" name="wlSLA"/>
        </td>

    </tr>
    <tr>
        <td class="al_r" width="20%">
            <label>库位:</label>
        </td>
        <td width="30%">
            <select name="wLocaltion">
                <c:forEach items="${types}" var="types">
                    <option value="${types.typecode}">${types.typename}</option>
                </c:forEach>
            </select>
        </td>
        <td class="al_r" width="20%">
            <label>发货SLA:</label>
        </td>
        <td width="30%">
            <select name="fhSLA">
                <c:forEach items="${fhSLAs}" var="sla">
                    <option value="${sla.typecode}">${sla.typename}</option>
                </c:forEach>

            </select>
        </td>
    </tr>
    <tr>
        <td class="al_r" width="20%" valign="top">
            <label>提货地址:</label>
        </td>
        <td colspan="3">
            <select style="width: auto;" id="province" onchange="loadCity()" name="thSheng.id">
                <c:forEach items="${territoryList }" var="terr">
                    <option value="${terr.id }">${terr.territoryName }</option>
                </c:forEach>
            </select>
            <select style="width: auto;" id="city" name="thCity.id">
            </select>
            <input name="thAddress"/>
        </td>
    </tr>
    <tr>
        <td class="al_r" width="20%" valign="top">
            <label>发货说明:</label>
        </td>
        <td colspan="3">
            <textarea style="width: 100%; height: 60px;" name="deliverDes" ></textarea>
            <input type="hidden" id="ids" name="EquipmentIds"/>
            <input type="hidden" value="${ids}" name="ids"/>
        </td>
    </tr>
    </tbody>
</table>

<div><span style="font-weight: bold;">选择返件物流</span></div>
<table class="nobordertable noborder" style="border: none;">
    <tbody>
    <tr>
        <td class="al_r" width="20%">
            <label>物流:</label>
        </td>
        <td width="30%">
            <select id="return_logistics" onchange="getPersonMessage()" name="returnLogistics">
                <option value="0">--请选择物流--</option>
                <c:forEach items="${tsDepartList}" var="tsDe">
                    <option value="${tsDe.departname}" <c:if test="${logisticsName == tsDe.departname}">selected="selected"</c:if>>${tsDe.departname}</option>
                </c:forEach>
            </select>
        </td>
        <td class="al_r" width="20%">
            <label>联系人:</label>
        </td>
        <td width="30%">
            <span id="personMsg">${returnContacts.name}&emsp;${returnContacts.cellphone1}&emsp;${returnContacts.email}</span>
        </td>
    </tr>
    <tr>
        <td colspan="2" style="text-align: right;">
            <a   class="easyui-linkbutton l-btn" id="btn" onclick="send()">发货</a>
        </td>
    </tr>
    </tbody>
</table>
</form>
<script>
    $(function () {
        $("#btn").css("pointer-events","auto");
    })
    function send() {
        $("#btn").css("pointer-events","none");
        var slaType = $("#slaType").text();
        $("#wlSLA").val(slaType);
        $.ajax({
            type:"post",
            dataType:"json",
            data:$("#myform").serialize(),
            url:"cbsDelinerController.do?send",
            success:function (data) {
                var obj = data.attributes;

                if(obj.sta==1){
                    tip("操作成功");
                    setTimeout("  addOneTab(\"发货管理\",'cbsDelinerController.do?cbsDeliner');",1000);
                    setTimeout("closetab('CSA合并发货')",1000);
                }else {
                    tip("操作失败");
                }
            }
        })
    }
</script>
</body>
</html>
